package com.dys.controller;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

/**
 * @className: com.dys.controller.ForwardAndRedirectController
 * @description: 通过servlet实现请求转发语响应重定向
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/26 21:54
 */
@Controller
public class ForwardAndRedirectController {

    @RequestMapping("/forward")
    public void forward(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("请求转发......");
        request.getRequestDispatcher("/forward.jsp").forward(request, response);
    }

    @RequestMapping("/redirect")
    public void redirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("响应重定向......");
        response.sendRedirect(request.getContextPath() + "/redirect.jsp");
    }
}
